package com.ruoyi.DegreePoints.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.DegreePoints.domain.DegreePoints;
import org.apache.ibatis.annotations.Select;

/**
 * 学位点Mapper接口
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
public interface DegreePointsMapper extends BaseMapper<DegreePoints>
{
    /**
     * 查询学位点
     * 
     * @param pointId 学位点主键
     * @return 学位点
     */
    @Select("select * from degree_points where point_id = #{pointId}")
    public DegreePoints selectDegreePointsByPointId(Long pointId);

    /**
     * 查询学位点列表
     * 
     * @param degreePoints 学位点
     * @return 学位点集合
     */
    public List<DegreePoints> selectDegreePointsList(DegreePoints degreePoints);

    /**
     * 新增学位点
     * 
     * @param degreePoints 学位点
     * @return 结果
     */
    public int insertDegreePoints(DegreePoints degreePoints);

    /**
     * 修改学位点
     * 
     * @param degreePoints 学位点
     * @return 结果
     */
    public int updateDegreePoints(DegreePoints degreePoints);

    /**
     * 删除学位点
     * 
     * @param pointId 学位点主键
     * @return 结果
     */
    public int deleteDegreePointsByPointId(Long pointId);

    /**
     * 批量删除学位点
     * 
     * @param pointIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteDegreePointsByPointIds(Long[] pointIds);




    @Select("SELECT * \n" +
            "FROM degree_points dp\n" +
            "WHERE dp.point_id IN (\n" +
            "    SELECT ea.point_id \n" +
            "    FROM expert_assignments ea \n" +
            "    WHERE expert_id = #{userId}\n" +
            ")\n")
    public List<DegreePoints> selectByExpertId(Long userId);


    //根据uID 查询学位点信息
    @Select("select * from degree_points where user_id = #{userId}")
    DegreePoints selectByUId(Long userId);

    //查询经费总额
    @Select("SELECT SUM(funding) AS total_funding\n" +
            "FROM ceshi.research_projects\n" +
            "WHERE point_id = #{userId};")
    Long getResearchFunding(Long userId);
}
